package com.example.mapper;

import com.example.pojo.City;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

@Mapper
public interface CityMapper {


    public static List<City>getCities(){
        // 创建文件对象
        File file = new File("src/main/resources/static/places.txt");
        List<City> cities = new ArrayList<>();
        try {
            // 创建 Scanner 对象
            Scanner scanner = new Scanner(file);

            // 逐行读取文件内容并解析为 City 对象
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                String[] parts = line.split(",");
                int id = Integer.parseInt(parts[0]);
                String name = parts[1];
                String longitude = parts[2];
                String latitude = parts[3];
                City city = new City(id, name, longitude, latitude);
                cities.add(city);
            }

            scanner.close();
        } catch (FileNotFoundException e) {
            System.out.println("找不到文件。");
            e.printStackTrace();
        }

        return cities;
    };
    @Update("update  place set lng=#{lng}, lat=#{lat}  where id=#{id}")
    void save(City city);
}
